//
//  NavigationView.m
//  YiTangZuoWenKe
//
//  Created by Work on 17/2/21.
//  Copyright © 2017年 Work. All rights reserved.
//

#import "NavigationView.h"
@implementation NavigationView

- (instancetype)initWithFrame:(CGRect)frame withLeftImageUrl:(NSArray *)leftUrlArray  withRighitImageUrl:(NSArray *)rightUrlArray withRightStr:(NSArray *)rightStrArray withColor:(UIColor *)color{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        [self creatWithLeftUrl:leftUrlArray withRightUrl:rightUrlArray withRightStr:rightStrArray withColcor:color];
    }
    
    return self;
}

- (void)creatWithLeftUrl:(NSArray*)leftUrlArray withRightUrl:(NSArray *)rightUrlArray withRightStr:(NSArray *)rightStrArray withColcor:(UIColor*)color{
    
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftBtn.frame = CGRectMake(15, 31, 27, 27);
    [self.leftBtn setImage:[UIImage imageNamed:[leftUrlArray objectAtIndex:0]] forState:UIControlStateNormal];
    [self.leftBtn setImage:[UIImage imageNamed:[leftUrlArray objectAtIndex:1]] forState:UIControlStateHighlighted];
    [self.leftBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.leftBtn];
    
    self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.rightBtn];
    if (rightUrlArray!=nil) {
        self.rightBtn.frame = CGRectMake(KSCREEWIDTH - 36, 31, 27, 27);
        [self.rightBtn setImage:[UIImage imageNamed:[rightUrlArray objectAtIndex:0]] forState:UIControlStateNormal];
        [self.rightBtn setImage:[UIImage imageNamed:[rightUrlArray objectAtIndex:1]] forState:UIControlStateSelected];
    }
    if (rightStrArray!=nil) {
        
        [self.rightBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).with.offset(-9);
            make.top.equalTo(self.mas_top).with.offset(31);
            
        }];
        self.rightBtn.titleLabel.font = H14;
        [self.rightBtn setTitle:[rightStrArray objectAtIndex:0] forState:UIControlStateNormal];
        [self.rightBtn setTitle:[rightStrArray objectAtIndex:1] forState:UIControlStateSelected];
        
        if (color!=nil) {
            [self.rightBtn setTitleColor:color forState:UIControlStateNormal];
            [self.rightBtn setTitleColor:color forState:UIControlStateSelected];
        }
    }
    [self.rightBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(KSCREEWIDTH/2-75, CGRectGetMinY(self.leftBtn.frame),150, self.leftBtn.frame.size.height)];
    self.titleLabel.textColor = COLOR3;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.titleLabel];

    
    if (rightStrArray ==nil && rightUrlArray == nil) {
        
        self.rightBtn.hidden = YES;
    }
    
    self.line = [[UIView alloc]initWithFrame:CGRectMake(0, 63.2, KSCREEWIDTH, 0.8)];
    self.line.backgroundColor = COLOR5;
    [self  addSubview:self.line];
    
}

-(void)click:(UIButton *)sender{
    
    if (sender == self.leftBtn) {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(navigtionleftBackclick:)]) {
            
            [self.delegate navigtionleftBackclick:sender];
        }
        
    }
    
    if (sender == self.rightBtn) {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(navigtionleftBackclick:)]) {
            
            [self.delegate navigtionrightBackclick:sender];
        }
        
    }
    
}

@end
